package com.hzhr.iot.meterplan.service.util;

import com.hzhr.iot.core.constant.Common_ErrorsEnum;
import com.hzhr.iot.core.constant.HzhrHeaderNames;
import com.hzhr.iot.core.exception.ServiceException;
import org.springframework.util.StringUtils;

import java.util.HashMap;
import java.util.Map;

public class CheckUtil {
    public static void checkHeader(Map<String, String> header) throws ServiceException {
        if (header == null) {
            throw new ServiceException(Common_ErrorsEnum.COMMON_6, "header不能为空");
        }
        if (StringUtils.isEmpty(header.get(HzhrHeaderNames.USER_ID))) {
            Map<String, Object> objectInfo = new HashMap<>();
            objectInfo.put("header", header);
            throw new ServiceException(Common_ErrorsEnum.COMMON_6, "header." + HzhrHeaderNames.USER_ID + "不能为空", objectInfo);
        }
        if (StringUtils.isEmpty(header.get(HzhrHeaderNames.USER_CODE))) {
            Map<String, Object> objectInfo = new HashMap<>();
            objectInfo.put("header", header);
            throw new ServiceException(Common_ErrorsEnum.COMMON_6, "header." + HzhrHeaderNames.USER_ID + "不能为空", objectInfo);
        }
        if (StringUtils.isEmpty(header.get(HzhrHeaderNames.USER_NAME))) {
            Map<String, Object> objectInfo = new HashMap<>();
            objectInfo.put("header", header);
            throw new ServiceException(Common_ErrorsEnum.COMMON_6, "header." + HzhrHeaderNames.USER_ID + "不能为空", objectInfo);
        }
        if (StringUtils.isEmpty(header.get(HzhrHeaderNames.TRANSACTION_ID))) {
            Map<String, Object> objectInfo = new HashMap<>();
            objectInfo.put("header", header);
            throw new ServiceException(Common_ErrorsEnum.COMMON_6, "header." + HzhrHeaderNames.USER_ID + "不能为空", objectInfo);
        }
        if (StringUtils.isEmpty(header.get(HzhrHeaderNames.TRANSACTION_TYPE))) {
            Map<String, Object> objectInfo = new HashMap<>();
            objectInfo.put("header", header);
            throw new ServiceException(Common_ErrorsEnum.COMMON_6, "header." + HzhrHeaderNames.USER_ID + "不能为空", objectInfo);
        }
    }
}
